//
//  DiscoverTableViewCell.m
//  ZYZB
//
//  Created by ENERGY on 2018/7/4.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "DiscoverTableViewCell.h"

@interface DiscoverTableViewCell()
@property (nonatomic, strong)UILabel * titleLab;//一级标题
@property (nonatomic, strong)UILabel * subTitleLab;//二级标题
@property (nonatomic, strong)UILabel * dateLab;//日期
@property (nonatomic, strong)UIImageView * newsImg;//图片
@property (nonatomic, strong)NSString * newsID;
@end
@implementation DiscoverTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        __weak typeof (self)weakSelf = self;
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.subTitleLab];
        [self.contentView addSubview:self.dateLab];
        [self.contentView addSubview:self.newsImg];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).mas_offset(19/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contentView.mas_top).mas_offset(22/WIDTH_6_SCALE);
            make.width.mas_offset(180/WIDTH_6_SCALE);
            make.height.mas_offset(36/WIDTH_6_SCALE);
//            make.height.mas_offset(35/WIDTH_6_SCALE);
        }];
        [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.width.equalTo(weakSelf.titleLab);
            make.height.mas_offset(11/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.titleLab.mas_bottom).mas_offset(10/WIDTH_6_SCALE);
        }];
        [self.dateLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.subTitleLab.mas_bottom).mas_offset(11/WIDTH_6_SCALE);
            make.left.width.height.equalTo(weakSelf.subTitleLab);
        }];
        [self.newsImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.titleLab.mas_right).mas_offset(25/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contentView.mas_top).mas_offset(20/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.contentView.mas_bottom).mas_offset(-20/WIDTH_6_SCALE);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-18/WIDTH_6_SCALE);
        }];
        UIView * lineView = [[UIView alloc] init];
        lineView.backgroundColor = getColor(borderColor);
        [self.contentView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf.contentView);
            make.height.mas_offset(1/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.mas_bottom).mas_offset(-1/WIDTH_6_SCALE);
        }];
    }return self;
}
#pragma mark - init
- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = DEF_FontSize_14;
        _titleLab.textColor = [UIColor blackColor];
        _titleLab.textAlignment = NSTextAlignmentLeft;
        _titleLab.numberOfLines = 2;
        _titleLab.lineBreakMode = NSLineBreakByWordWrapping;
        _titleLab.text = @"中国实体经济未来五到十年将有质的提高";
    }return _titleLab;
}
- (UILabel *)subTitleLab{
    if (!_subTitleLab) {
        _subTitleLab = [[UILabel alloc] init];
        _subTitleLab.font = DEF_FontSize_10;
        _subTitleLab.textColor = getColor(@"bcbcbc");
        _subTitleLab.textAlignment = NSTextAlignmentLeft;
        _subTitleLab.text = @"4月9日，央行有关负责人就到国务院办公";
    }return _subTitleLab;
}
- (UILabel *)dateLab{
    if (!_dateLab) {
        _dateLab = [[UILabel alloc] init];
        _dateLab.font = DEF_FontSize_10;
        _dateLab.textColor = getColor(@"bcbcbc");
        _dateLab.textAlignment = NSTextAlignmentLeft;
        _dateLab.text = @"2018-04-28  15:34:08";
    }return _dateLab;
}
- (UIImageView *)newsImg{
    if (!_newsImg) {
        _newsImg = [[UIImageView alloc] init];
        _newsImg.backgroundColor = [UIColor redColor];
        _newsImg.layer.cornerRadius = 4;
        _newsImg.layer.masksToBounds = YES;
    }return _newsImg;
}
- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.titleLab.text = model[@"infoTitle"];
    self.subTitleLab.text = model[@"infoIntro"];
    self.newsID = model[@"dbid"];
    [self.newsImg sd_setImageWithURL:[NSURL URLWithString:model[@"infoImg"]] placeholderImage:[UIImage imageNamed:@"3"]];
    self.dateLab.text = model[@"infoTime"];
}
@end
